/*pmFWCFu5nhKkBzYmrkBakV0bJk4JW5gQtRRkgMJz728LT5N2JTIvOitt7vMR49l2*/
import { pageConfig } from '../const';
import afterEvent from './afterEvent';
import fa from 'fa';
const { fa_components } = fa;
const { ReferFilter } = fa_components;
const { addSearchAreaReferFilter } = ReferFilter;

import ampub from 'ampub';
const { commonConst: { CommonKeys: { IBusiRoleConst } } } = ampub;

/**
 * 模板初始化
 * @param {*} props 
 */
export default function(props) {
	let { pagecode } = pageConfig;

	let defaultConfig = {
		searchId: pageConfig.searchAreaId,
		specialFields: {
			// provider供应商 pk_jobmngfil项目	pk_usedept使用部门 pk_equip_usedept资产使用部门 pk_mandept管理部门 pk_assetuser使用人

			// 供应商
			provider: {
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_org' ],
						returnName: 'pk_org'
					}
				]
			},
			// 工程项目
			pk_jobmngfil: {
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_org' ],
						returnName: 'pk_org'
					}
				]
			},
            // 使用部门
			pk_usedept: {
                isRunWithChildren: true, //是否执行时包含下级
			    defaultRunWithChildren: true, //是否默认勾选执行时包含下级
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_equiporg', 'pk_org' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}
				]
			},
            
            // 资产使用部门
			pk_equip_usedept: {
                isRunWithChildren: true, //是否执行时包含下级
			    defaultRunWithChildren: true, //是否默认勾选执行时包含下级
				orgMulti: 'pk_org',
				data: [
					{
						fields: [  'pk_org' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}
				]
			},
            // 管理部门
			pk_mandept: {
                isRunWithChildren: true, //是否执行时包含下级
			    defaultRunWithChildren: true, //是否默认勾选执行时包含下级
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_ownerorg', 'pk_org' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}
				]
			},
            // 使用人
			pk_assetuser: {
                isRunWithChildren: true, //是否执行时包含下级
			    defaultRunWithChildren: true, //是否默认勾选执行时包含下级
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_equiporg', 'pk_org' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}
				]
			}
		}
	};

	props.createUIDom(
		{
			// 页面编码
			pagecode
		},
		(data) => {
			if (data) {
				if (data.template) {
					let meta = data.template;
					addSearchAreaReferFilter(props, meta, defaultConfig);
					meta[pageConfig.searchAreaId].items.map((item) => {
						if (item.attrcode === 'pk_transitype') {
							item.queryCondition = () => {
								return { parentbilltype: 'H1' };
							};
						}
						if (item.attrcode === 'pk_category') {
							item.queryCondition = () => {
								return { DataPowerOperationCode: 'default', isDataPowerEnable: true };
							};
						}
					});
					props.meta.setMeta(meta);
				}
				if (data.button) {
					let button = data.button;
					props.button.setButtons(button, () => {
						props.button.setButtonDisabled([ 'Print', 'Output', 'Preview' ], true);
					});
				}
				afterEvent.call(this, props);
			}
		}
	);
}

/*pmFWCFu5nhKkBzYmrkBakV0bJk4JW5gQtRRkgMJz728LT5N2JTIvOitt7vMR49l2*/